package demo1209.lianxi;

import java.util.Random;

//普通会员类:
//收红包的方法:
//参数:int[] arr  void
public class Member extends User {
    public Member(String name, double balance) {
        super(name, balance);
    }

    public Member() {
    }

    // [6, 0, 8]
    public void receive(int[] arr) {
        //假设红包被抢完
        int  index = -1;
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != 0) {
                index = i;
                break;
            }
        }
        if (index==-1){
            System.out.println("红包已被抢完,来晚了..");
            return;
        }

        Random r = new Random();
        index = r.nextInt(arr.length);//[0,2]

        while (arr[index] == 0) {
            index = r.nextInt(arr.length);
        }
        int hongbao = arr[index];
        arr[index] = 0;
        setBalance(getBalance() + hongbao);
    }


}
